package com.yanchangapp.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.RecordProductBean;
import com.yanchangapp.widget.ExpandLayout;
import com.zxl.baselib.util.formatter.BigDecimalUtils;
import com.zxl.baselib.util.time.TimeUtil;
import com.zxl.baselib.util.ui.ResHelper;
import com.zzhoujay.markdown.parser.Line;

import java.util.List;

/**
 * Created by apple on 2019-08-26.
 * description: item_product_record_approve
 */
public class GRecordProductAdapter extends BaseQuickAdapter<RecordProductBean, BaseViewHolder> {
    private boolean showSinglePrice;

    public void setShowSinglePrice(boolean singlePrice){
        this.showSinglePrice = singlePrice;
    }

    public GRecordProductAdapter(int layoutResId, @Nullable List<RecordProductBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RecordProductBean item) {
        // 设置背景
        CardView cardView =  helper.getView(R.id.cardView);
        switch (item.getPurchaseStatus()){
            case 2:
                cardView.setCardBackgroundColor(ResHelper.getColor(R.color.must_bg));
                break;
            case 1:
                cardView.setCardBackgroundColor(ResHelper.getColor(R.color.sug_bg));
                break;
            default:
                cardView.setCardBackgroundColor(ResHelper.getColor(R.color.normal_bg));
                break;
        }
        // 设置单价
        LinearLayout llSingle =  helper.getView(R.id.llSingle);
        if (showSinglePrice){
            llSingle.setVisibility(View.VISIBLE);
        }else {
            llSingle.setVisibility(View.GONE);
        }
        helper.setText(R.id.tvSinglePrice, BigDecimalUtils.keep2Decimal(item.getPrice()));
        helper.setText(R.id.tvProductFormat,item.getProductFormat());
        helper.setText(R.id.tvManufacturer, item.getManufacture());
        helper.setText(R.id.tvSupplierName, item.getSupplierName());
        helper.setText(R.id.tvTitle,item.getProductName());
        helper.setText(R.id.tvBuyNum,ResHelper.getString(R.string.product_buy_num,item.getPurchaseNum()));
        // 设置实际库存
        helper.setText(R.id.tvRealStore, ResHelper.getString(R.string.real_store,
                item.getInventoryNumber(),item.getAlarmMin(),item.getAlarmMax()));
        ImageView ivArrow = helper.getView(R.id.ivArrow);
        ExpandLayout expandLayout = helper.getView(R.id.expandLayout);
        expandLayout.initExpand(false,ivArrow,true);
        RelativeLayout rlHead = helper.getView(R.id.rlHead);
        rlHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                expandLayout.toggleExpand();
            }
        });
    }
}
